/*
 * $RCSfile: Processor_46_Msg.java,v $
 * $Revision: 1.1  $
 * $Date: 2012-8-16  $
 *
 * Copyright (C) 2005 Bettem, Inc. All rights reserved.
 *
 * This software is the proprietary information of Bettem, Inc.
 * Use is subject to license terms.
 */
package com.i366.processor;

import java.util.Map;

import org.apache.log4j.Logger;

import com.i366.Constant;
import com.i366.cache.Cache;
import com.i366.room.model.RoomPersion;
import com.i366.room.model.impl.Room;
import com.i366.service.RoomService;
import com.i366.util.DengJiUtil;
import com.work.client.util.I366ClientPickUtil;
import com.work.comm.util.I366PickUtil;
import com.work.db.model.UserInfo;
import com.work.engine.protocal.request.Request;
import com.work.engine.server.handler.Handler;

/**
 *
 * 获取用户基本信息
 * <p>Title: Processor_62_Persion</p> 
 * <p>Description: </p> 
 * <p>Copyright: Copyright (c) 2006</p> 
 * @author shenxing.ruan
 * @version 1.0
 */
public class Processor_62_Persion extends Handler{

	private Logger logger = Logger.getLogger(Processor_62_Persion.class);
	public byte[] handleRequest() {
		logger.debug("Processor_62_Persion userId is : " + this.getGameRequest().getUserId());
		//=======================相关验证=================
		Request request = getGameRequest();
		RoomService.updateUser(request);
		int[][] int2 = {{60,I366ClientPickUtil.TYPE_INT_1},
				{130,I366ClientPickUtil.TYPE_INT_4}
		};
		Map<Integer, Object> map = I366PickUtil.pickAll(request.getBt(), int2);
		int seatid = (Integer)map.get(60);
		int userid = (Integer)map.get(130);
		int roomUserId = request.getUserId();
		try {
			UserInfo userInfo = Cache.getOnlineUserInfo().get(roomUserId);
			if (userInfo == null) {
				return pusUser(1);
			}
			Room room = Cache.getRoom(userInfo.getRoomId(), userInfo.getRoomPath());
			if (room == null) {
				return pusUser(1);
			}
			RoomPersion rp = room.getAudMap().get(userid);
			if (rp == null) {
				return pusUser(1);
			}
			userInfo = rp.getUserInfo();
			Integer int5[];
			if (userInfo.getPocer() != null && userInfo.getPocer()[0] != null) {
				int5 = new Integer[5];
				int5[0] = userInfo.getPocer()[0].getSize1();
				int5[1] = userInfo.getPocer()[1].getSize1();
				int5[2] = userInfo.getPocer()[2].getSize1();
				int5[3] = userInfo.getPocer()[3].getSize1();
				int5[4] = userInfo.getPocer()[4].getSize1();
			}else {
				int5 = new Integer[0];
			}
			Object[][] objs = {
					{60,0,I366PickUtil.TYPE_INT_1},
					{61,userInfo.getSex(),I366PickUtil.TYPE_INT_1},
					{62,DengJiUtil.getDengKJ(userInfo.getJifen1()),I366PickUtil.TYPE_INT_1},
					{63,seatid,I366PickUtil.TYPE_INT_1},
					{130,userInfo.getUserId(),I366ClientPickUtil.TYPE_INT_4},
					{131,userInfo.getNikeName(),I366ClientPickUtil.TYPE_STRING_UTF16},
					{132,int5,I366ClientPickUtil.TYPE_INT_1_ARRAY},
					{133,userInfo.getBiggestwinRate(),I366ClientPickUtil.TYPE_INT_4},
					{134,userInfo.getChip(),I366ClientPickUtil.TYPE_INT_4},
					{135,userInfo.getWin(),I366ClientPickUtil.TYPE_INT_4},
					{136,userInfo.getLose(),I366ClientPickUtil.TYPE_INT_4},
					{137,userInfo.getJifen1(),I366ClientPickUtil.TYPE_INT_4},
					{138,userInfo.getJifen2(),I366ClientPickUtil.TYPE_INT_4},
					{139,userInfo.getHead(),I366ClientPickUtil.TYPE_STRING_UTF16}
			};
			byte[] bytes = I366PickUtil.packAll(objs, Constant.REQ_GAME_PLAYER_DATA);
			return bytes;
		} catch (Exception e) {
			logger.debug("发送消息出错", e);
			return pusUser(1);
		}
	}

	public byte[] pusUser(int status) {
		Object[][] objs2 = {
				{60,status,I366ClientPickUtil.TYPE_INT_1}
		};
		byte[] bytes = I366PickUtil.packAll(objs2, Constant.REQ_GAME_PLAYER_DATA);
		return bytes;
	}

	public Object makeObject() throws Exception {
		return new Processor_62_Persion();
	}

}

